package demo;

import java.util.Scanner;

public class Test {
    public static void func1(Animal animal) {
        animal.eat();
    }
    public static Animal func(int q) {
        Scanner in = new Scanner(System.in);
        if(q == 1) {
            System.out.print("输入名字：");
            String s = in.nextLine();
            System.out.print("输入年龄：");
            int b = in.nextInt();
            return new Dog(s,b);
        }else {
            System.out.print("输入名字：");
            String s = in.nextLine();
            System.out.print("输入年龄：");
            int b = in.nextInt();
            return new Cat(s,b);
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int q = 0;
        do {
            System.out.println("请输入你的身份：1(dog)/2(cat)");
            q = in.nextInt();
            Animal animal = func(q);
            animal.eat();
        }while (q == 1 || q == 2);

    }
}
